package cn.weekdragon.gscore.adapter.bot;

import cn.hutool.core.util.StrUtil;
import java.util.Collection;
import java.util.List;
import java.util.Optional;
import java.util.concurrent.ConcurrentHashMap;

public class BotManager {

    private static final ConcurrentHashMap<String, Bot> ID_MAP = new ConcurrentHashMap<>();
    private static final ConcurrentHashMap<String, Bot> NAME_MAP = new ConcurrentHashMap<>();


    public static Optional<Bot> getBotByName(String name){
        return Optional.ofNullable(NAME_MAP.get(name));
    }

    public static Optional<Bot> getBotById(String id){
        return Optional.ofNullable(ID_MAP.get(id));
    }

    public static void removeBot(Bot bot) {
        ID_MAP.remove(bot.getBotId());
        NAME_MAP.remove(bot.getBotId());
    }

    public static void addBot(Bot bot) {
        String botId = bot.getBotId();
        if(StrUtil.isNotEmpty(botId)){
            ID_MAP.put(botId,bot);
        }
        String botName = bot.getBotName();
        if(StrUtil.isNotEmpty(botName)){
            NAME_MAP.put(botName,bot);
        }
    }

    public static Collection<Bot> getBots() {
        return NAME_MAP.values();
    }
}